var e = require;
var t = module;
var n = exports;
"use strict";
Object.defineProperty(n, "__esModule", { value: !0 });
var o = e("ConfigConst"),
    i = e("ConfigManager"),
    r = ["logo"];
window.GameLanguage = {}, window.LanguageLabel = {};
Object.defineProperty(y, "instance", {
        get: function() { return this._instance || (this._instance = new y), this._instance },
        enumerable: !1,
        configurable: !0
    }), Object.defineProperty(y.prototype, "lan", {
        get: function() { return this._lan },
        set: function(e) {
            this.lastLan = this._lan, this._lan = e,
                this.updateLan()
        },
        enumerable: !1,
        configurable: !0
    }), y.prototype.setFont = function(e) { this._font = e },
    y.prototype.init = function() {
        var e = this;
        try {
            var t = cc.sys.language,
                n = cc.sys.languageCode;
            "zh" === t ? -1 != n.indexOf("hant") || -1 != n.indexOf("tw") || -1 != n.indexOf("hk") || -1 != n.indexOf("mo") ? this.lan = "tw" : this.lan = "zh" : this.lan = "ja" == t ? "ja" : "en", console.log("[Language] --\x3e 初始化语言:  lan: " + this.lan + " systype: " + t + " syscode: " + cc.sys.languageCode),
                cc.game.emit("language-init", this.lan)
        } catch (e) {}
        Object.defineProperty(cc.Label.prototype, "string", {
            get: function() { return this._string },
            set: function(e) {
                var t = this._string,
                    n = e;
                (n = window.GameLanguage && window.GameLanguage[e] ? window.GameLanguage[e] || "" : n) && "number" != typeof n && (n = n.replace("<br/>", "\n")), this._string = "" + n, this.string !== t && this.setVertsDirty(), this._checkStringEmpty()
            }
        }), cc.Label.prototype.onLoad = function() {
            this._batchAsBitmap && this.cacheMode === cc.Label.CacheMode.NONE && (this.cacheMode = cc.Label.CacheMode.BITMAP, this._batchAsBitmap = !1), cc.game.renderType === cc.game.RENDER_TYPE_CANVAS && (this.cacheMode = cc.Label.CacheMode.NONE), e._font && this.font != e._font && (this.font = e._font, this.lineHeight == this.fontSize && (this.lineHeight += 2)), this.string = this.string
        }, cc.RichText.prototype.start = function() {
            e._font && (this.font = e._font), this._onTTFLoaded()
        }, cc.Sprite.prototype.onLoad = function() {
            var e, n, o, i = this;
            this.spriteFrame && (e = this.spriteFrame.name, -1 != r.indexOf(e) && e && (n = "texture/language/" + y.instance.lan + "/" + e, o = this.node.opacity, this.node.opacity = 0, this.spPath = n, cc.loader.loadRes(n, cc.SpriteFrame, function(e, t) { i.node.opacity = o, e || i.spPath == n && (i.spriteFrame = t) })))
        }
    }, y.prototype.updateLan = function() {
        // var n = this;
        // i.Config.get(o.ConfigConst.LANGUAGE).then(function(e) {
        //     for (var t in e) {
        //         t = e[t];
        //         window.GameLanguage[t.zh] = t[n.lan]
        //     }
        // })
    }, y.formatStr = function(e) {
        for (var t = [], n = 1; n < arguments.length; n++) t[n - 1] = arguments[n];
        var o = e,
            e = window.GameLanguage;
        e && e[o] && (o = e[o]);
        var i = /(%d)|(%s)/,
            r = /%s/,
            y = arguments.length;
        if (0 === y) return "";
        if (1 === y) return "" + o;
        if ("string" == typeof o && i.test(o))
            for (var a = 1; a < y; ++a) {
                var s, c, x = arguments[a],
                    l = "number" == typeof x ? i : r;
                l.test(o) ? (s = x, (c = window.GameLanguage) && c[x] && ((c = c[x]) && (s = c)), o = o.replace(l, s)) : o += "" + x
            } else
                for (a = 1; a < y; ++a) o += " " + arguments[a];
        return o
    }, y._instance = null, e = y;

function y() { this.lastLan = "zh", this._lan = "zh", this._font = null }
n.default = e